<cfcomponent extends="Controller">
	<cffunction name="init">
		<cfscript>
			THIS.navigation = [
				{	"home" 				= 0	},
				{ 	"about" 			= 0	},
				{ 	"lessons" 			= 0	},
				{ 	"calendar" 			= 0	},
				{	"testimonials" 		= 0	},
				{	"contact" 			= 0 }
			];
			
			set(navigation = THIS.navigation);
			filters(through="setNavigation");
		</cfscript>
	</cffunction>

	<cffunction name="setNavigation">
		<cfscript>
			THIS.navigation = get("navigation");
			
			for(intRow = 1; intRow LTE ArrayLen(THIS.navigation); intRow++) {
				if(StructKeyExists(THIS.navigation[intRow], PARAMS.action))
					THIS.navigation[intRow][PARAMS.action] = [];
			}

			set(navigation = THIS.navigation);
			navigation = get("navigation");
		</cfscript>
	</cffunction>

	<cffunction name="signin">
		<cfscript>
			PARAMS.email = PARAMS['email'];
			
			user = model("user").findOneByEmailAndPassword("#PARAMS.email#,#PARAMS.password#");

			if(IsObject(user)) {
				SESSION.user = {};

				for(column IN ListToArray("id,login_type,email,first_name,last_name")) {
					SESSION.user[column] = user[column];
				};

				if(SESSION.user.login_type IS "P")
					redirectTo(controller="main", action="profile");
				else redirectTo(controller="main", action="admin");
			} else {
				flashInsert(error="The <strong><em>Email</em></strong> or <strong><em>Password</em></strong> you have entered is incorrect!");
				RenderPage(controller="main", action="login");
			}
		</cfscript>
	</cffunction>

	<cffunction name="logout">
		<cfscript>
			StructClear(SESSION);
			flashInsert(success="You have successfully logged out!");
			RenderPage(controller="main", action="login");
		</cfscript>
	</cffunction>

	<cffunction name="calendar">
	</cffunction>

	<cffunction name="profile">
		<cfscript>
			if(NOT StructKeyExists(SESSION, "User")) {
				redirectTo(controller="main", action="login");
				flashInsert(error="Sorry You have been logged out due to inactivity!");
			}

			student = {
				"info" = model("parent").findAllByLast_Name(key="Fuchs", include="parentStudents(student)"),	//SESSION.user.last_name
				"notes" = model("studentNote").findAllByStudent_ID(1) 			//SESSION.user.id
				,"goals" = model("studentGoal").findAllByStudent_ID(1)			//SESSION.user.id
			};
		</cfscript>
	</cffunction>

	<cffunction name="home">
		<cfscript>
			if(StructKeyExists(SESSION, "user")) {
				StructClear(SESSION);
			}
		</cfscript>
	</cffunction>

	<cffunction name="admin">
		<cfscript>
			adminSections = ListToArray("parents,students,employees");
		</cfscript>
	</cffunction>
</cfcomponent>